package jp.sourceforge.akjrcp.audiotools;

import jp.sourceforge.akjrcp.akj_betas.Messages;
import jp.sourceforge.akjrcp.commons.ui.widget.WidgetBuilder;
import jp.sourceforge.akjrcp.ui.LabelTextLabel;
import jp.sourceforge.akjrcp.ui.LayoutDataBuilder;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

/*
 * still development?
 */
public class SubtitleDialog extends MessageDialog{
		private LabelTextLabel startData;
		private LabelTextLabel endData;
		private LabelTextLabel durationData;
		private Text textArea;
		private String text="";
		private long startTime;
		private long duration;
		public SubtitleDialog(Shell parentShell, String dialogTitle, Image dialogTitleImage, int dialogImageType, String[] dialogButtonLabels, int defaultIndex) {
			super(parentShell, dialogTitle, dialogTitleImage, "",
					dialogImageType, dialogButtonLabels, defaultIndex);

		}
		
		  protected Control createCustomArea(Composite root) {
			  root.setLayout(new GridLayout(1,false));
		        
			    startData=new LabelTextLabel(root,SWT.NULL,Messages.getString("subtitleDialog.start"),""+startTime,Messages.getString("subtitleDialog.ms"),false);
			    startData.getMainText().addModifyListener(new ModifyListener(){
					public void modifyText(ModifyEvent e) {
						startTime=Long.parseLong(startData.getText());
						updateEndLabel();
					}});
			    startData.setLayoutData(LayoutDataBuilder.hintGridData(150, 0), LayoutDataBuilder.hintGridData(100, 0), null);
			    startData.getMainText().setOrientation(SWT.RIGHT_TO_LEFT);
			    
			    endData=new LabelTextLabel(root,SWT.NULL,Messages.getString("subtitleDialog.end"),""+(startTime+duration),Messages.getString("subtitleDialog.ms"));
			    endData.getMainText().setOrientation(SWT.RIGHT_TO_LEFT);
			    
			    
			    endData.setLayoutData(LayoutDataBuilder.hintGridData(150, 0), LayoutDataBuilder.hintGridData(100, 0), null);
			    
			    durationData=new LabelTextLabel(root,SWT.NULL,Messages.getString("subtitleDialog.duration"),""+duration,Messages.getString("subtitleDialog.ms"),false);
			    durationData.getMainText().setOrientation(SWT.RIGHT_TO_LEFT);
			    durationData.getMainText().addModifyListener(new ModifyListener(){
					public void modifyText(ModifyEvent e) {
						duration=Long.parseLong(durationData.getText());
						updateEndLabel();
					}});
			    durationData.setLayoutData(LayoutDataBuilder.hintGridData(150, 0), LayoutDataBuilder.hintGridData(100, 0), null);
			    
			    WidgetBuilder.createLabel(root,"text").setAlignment(SWT.CENTER);
			    
			    textArea=WidgetBuilder.createTextArea(root, text);
			    textArea.addModifyListener(new ModifyListener(){
					public void modifyText(ModifyEvent e) {
						text=textArea.getText();
					}});
			    textArea.setLayoutData(LayoutDataBuilder.hintGridData(-1, 100));
		        return root;
		    }

		  public void updateEndLabel(){
			  endData.getMainText().setText(""+(startTime+duration));
		  }
	

	}
